import {Component, onMounted, onWillStart, reactive, useChildSubEnv, useRef, useState, useSubEnv, xml} from "@odoo/owl";
import {makeEnv, mountComponent, startServices} from "@web/env";

import {Registry, registry} from "@/core/registry";

import {
    useAutofocus,
    useBus,
    useChildRef,
    useForwardRefToParent,
    useService,
    useSpellCheck,
} from "@web/core/utils/hooks";
import {CheckBox} from "@web/core/checkbox/checkbox";
import {
    click,
    getFixture,
    patchWithCleanup,
    mount,
    triggerEvent,
    triggerHotkey,
    nextTick, makeDeferred,
} from "@web/../tests/helpers/utils";
import {Notebook} from "@web/core/notebook/notebook";
import {NameAndSignature} from "@web/core/signature/name_and_signature";
import {ResizablePanel} from "@web/core/resizable_panel/resizable_panel";

import {session} from "@web/session";
import {currencies, formatCurrency} from "@web/core/currency";
import {useTransition} from "@/core/transition";
import {ModelSelector} from "@web/core/model_selector/model_selector";
import {ModelFieldSelector} from "@web/core/model_field_selector/model_field_selector";
import {AutoComplete} from "@web/core/autocomplete/autocomplete";
import {Deferred} from "@/core/utils/concurrency";
import {AccordionItem} from "@web/core/dropdown/accordion_item";
import {DateTimeInput} from "@web/core/datetime/datetime_input";
import {Dropdown} from "@web/core/dropdown/dropdown";
import {CheckboxItem} from "@web/core/dropdown/checkbox_item";
import {DropdownItem} from "@web/core/dropdown/dropdown_item";
import {Logger} from "sass";
import {ExpressionEditorDialog} from "@web/core/expression_editor_dialog/expression_editor_dialog";
import {Domain} from "@web/core/domain";

const mainComponentsRegistry = registry.category("main_components");
import {CodeEditor} from "@web/core/code_editor/code_editor";
import {
    complexCondition,
    condition,
    connector,
    domainFromExpression,
    domainFromTree,
    expression,
    Expression,
    expressionFromDomain,
    expressionFromTree,
    treeFromDomain,
    treeFromExpression,
} from "@web/core/tree_editor/condition_tree";
import {DomainSelector} from "@web/core/domain_selector/domain_selector";
import {DomainSelectorDialog} from "@web/core/domain_selector_dialog/domain_selector_dialog";
import {Popover} from "@web/core/popover/popover";
import {RecordSelector} from "@web/core/record_selectors/record_selector";
import {MultiRecordSelector} from "@web/core/record_selectors/multi_record_selector";
import {SelectMenu} from "@/core/select_menu/select_menu";
import {LoadingIndicator} from "@web/webclient/loading_indicator/loading_indicator";

import {NavBar} from "@web/webclient/navbar/navbar";
import {overlayService} from "@/core/overlay/overlay_service";
import {menuService} from "@/webclient/menus/menu_service";
import {actionService} from "@/webclient/actions/action_service";
import {notificationService} from "@/core/notifications/notification_service";
import {hotkeyService} from "@/core/hotkeys/hotkey_service";
import {uiService} from "@/core/ui/ui_service";
import {UserMenu} from "@web/webclient/user_menu/user_menu";

import {SearchBarMenu} from "@web/search/search_bar_menu/search_bar_menu";

import {WithSearch} from "@web/search/with_search/with_search";

import {localization} from "@web/core/l10n/localization";
import {_t} from "@/core/l10n/translation";
import {WeekDays} from "@/views/widgets/week_days/week_days";
import {useViewButtons} from "@/views/view_button/view_button_hook";
import {Layout} from "@web/search/layout";
import {getDefaultConfig, View} from "@/views/view";
import {makeView} from "@/components/help";


const userMenuRegistry = registry.category("user_menuitems");


export class FormDemo extends Component {
    setup() {

        this.popover = useService('popover')
        this.orm = useService('orm')
        this.localization = useService('localization')
        this.ui = useService('ui')
        this.field = useService('field')
        this.hotkey = useService('hotkey')
        this.notification = useService('notification')
        this.rpc = useService('rpc')
        this.menu = useService('menu')
        this.views = useService('view')
        this.fieldService = useService("field");

        this.rootRef = useRef('root')
        const rootRef = useRef("root");
        const btnRef = useRef("btn");

        onWillStart(async () => {
            // await this.orm.fieldg
            const fields = await this.fieldService.loadFields("sale.order");

            const {props, viewEnv} = makeView({
                type: "form",
                resModel: "sale.order",
                resId: 37,
                viewId: 891,
                searchViewId: 893,
                fields,
                // arch: `
                // <tree editable="bottom">
                //     <field name="name" />
                // </tree>`,
                arch: `
                <form>
                    <sheet>
                        <group>
                            <field name="name" />
                            <field name="user_id" />
                            <field name="create_date" />
                        </group>
                    </sheet>
                </form>`,
            })
            this.viewProps = props


        })


        this.onClick = async () => {

        }

    }


}

FormDemo.template = "FormDemo";
FormDemo.props = ['*']
FormDemo.components = {
    View,
    CheckBox,
    WithSearch,
    SearchBarMenu,
    LoadingIndicator,
    NavBar,
    SelectMenu,
    MultiRecordSelector,
    RecordSelector,
    Popover,
    DomainSelectorDialog,
    DomainSelector,
    CodeEditor,
    ExpressionEditorDialog,
    Dropdown,
    DropdownItem,
    AccordionItem,
    CheckboxItem,
    DateTimeInput
};

